package hmall.gateway.filter;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PrintAnyGatewayFilterFactory extends AbstractGatewayFilterFactory<PrintAnyGatewayFilterFactory.Config> {
    @Override
    public GatewayFilter apply(Config config) {
        return (exchange, chain) -> {
            System.out.println("过滤器执行了!" + config);
            return chain.filter(exchange);
        };
    }

    @Data
    static class Config {
        private String name;
        private String city;
        private String sex;
    }

    @Override
    public List<String> shortcutFieldOrder() {
        return List.of("name", "city", "sex");
    }

    public PrintAnyGatewayFilterFactory() {
        super(Config.class);
    }

    @Override
    public Class<Config> getConfigClass() {
        return super.getConfigClass();
    }
}
